import { defineStore } from 'pinia'
import { getDeptTree } from '@/api/public'

const usePublicStore = defineStore('public', {
  state: (): API.PublicState => ({
    department: <Partial<API.DepartmentItem>[]>[]
  }),
  actions: {
    /** 获取部门数据 */
    async fetchDeptTree() {
      const res = await getDeptTree()
      if (res?.code === 200) {
        this.department!.push(
          JSON.parse(JSON.stringify(res.data[0]).replace(/id/g, 'value'))
        )
        console.log(this.department)
      }
    }
  }
})

export default usePublicStore
